<?php
        include_once 'xmlrpc.inc';
	include_once 'Session.php';

	class ParkInfo {
		private $park_out;
		public function __construct($park_out)
		{
			$this->park_out = $park_out;
		}
		public function getNome()
		{	
			return $this->park_out['nome'];
		}
		public function getPostiDisponibili()
		{
			return $this->park_out['posti_disponibili'];
		}
		public function getPostiTotali()
		{
			return $this->park_out['posti_totali'];
		}
		public function isValido()
		{
			return $this->park_out['valido'];
		}

	}
	class Parking {
		private $token_id;
		private $url_parking_service;

		public function __construct() {
			$this->url_parking_service = new xmlrpc_client("http://muovi.roma.it/ws/xml/parcheggi/1");
			$this->token_id = $_SESSION['token_id'];
		} 


		public function getParks() {
			$parking_req = new xmlrpcmsg('parcheggi.Lista', array( new xmlrpcval($this->token_id, "string"), ));
			$result = $this->url_parking_service->send($parking_req);
			
			$parking_info_out = array();
			if (!$result->faultCode())
			{
				$value_parking_resp = $result->value();
				$resp = $value_parking_resp->structMem("risposta");
				for ($i = 0; $i < $resp->arraySize(); $i++)
				{
					$val = $resp->arrayMem($i);
					$id_parking = $val->structMem("id_parcheggio")->scalarVal();
					$nome = $val->structMem("nome")->scalarVal();
					$posti_disponibili = $val->structMem("posti_disponibili")->scalarVal();
					$posti_totali = $val->structMem("posti_totali")->scalarVal();
					$valido = $val->structMem("valido")->scalarVal();
					$n = array("nome"=>$nome,"posti_disponibili"=>$posti_disponibili,"posti_totali"=>$posti_totali, "valido"=>$valido); 
					$park_info = new ParkInfo($n);
					$park_info_out[] = $park_info;
				}
			}
			else
			{
				throw new Exception("Errore richiesta parcheggi<br/>");
			}
			return $park_info_out;
		}
		
	}
?>
